package com.atguigu.sparkstreaming.demos

/**
 * Created by Smexy on 2022/7/16
 *
 *  模式匹配。
 *    如果有一个集合，集合中元素的类型都是 () Tuple,可以使用模式匹配去处理Tuple
 *
 *      Tuple:  ()
 *      Tuple: (a)
 *      Tuple2: (a,b)
 *      Tuple3: (a,b,c)
 *      ...
 *      22个
 */
object TupleMatchDemo {

  def main(args: Array[String]): Unit = {

    val array: Array[(String, Int)] = Array(("zhangsan", 20), ("lisi", 30))

    //不用模式匹配
    array.foreach( (ele:(String, Int)) => {

      println("name:"+ele._1)
      println("age:"+ele._2)

    } )

    array.foreach{
      case (name111, age222) =>{

        println("name:"+name111)
        println("age:"+age222)

      }
    }

    val array1: Array[(String, Int,Double)] = Array(("zhangsan", 20, 22d), ("lisi", 30,33d))

    array1.foreach( (ele:(String, Int,Double)) => {

      println("name:"+ele._1)
      println("age:"+ele._2)
      println("salary:"+ele._3)

    } )

    array1.foreach{
      case (name, age,salary) =>{

        println("name:"+name)
        println("age:"+age)
        println("salary:"+salary)

      }
    }



  }

}
